package state;

import lombok.Getter;
import lombok.Setter;

/**
 * 切换状态
 */
public class RaffleActivity {

    @Setter
    private State state;
    private int count; //奖品数量
    @Getter
    @Setter
    private int points;// 积分
    @Getter
    private State noRaffleState = new NoRaffleState(this);
    @Getter
    private State canRaffleState = new CanRaffleState(this);
    @Getter
    private State dispenseState = new DispenseState(this);
    @Getter
    private State dispenseOutState = new DispenseOutState(this);

    public RaffleActivity(int count, int points) {
        this.state = getNoRaffleState();
        this.count = count;
        this.points = points;
    }

    //扣除积分
    public void deductPoints() {
        if (points >= 50) {
            state.deductPoints(points);
        } else {
            System.out.println("积分不足，不能抽奖");
            state = getNoRaffleState();
        }
    }

    public void raffle() {
        // 如果当前的状态是抽奖成功
        if (state.raffle()) {
            //领取奖品
            state.dispensePrize();
        }
    }

    // 领取奖品
    public int getCount() {
        int curCount = count;
        count--;
        return curCount;
    }
}
